package com.yanqu.road.server.cmd.activity.dragonboatrace;

import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.dragonboatrace.DragonBoatRaceProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.dragonboatrace.DragonBoatRaceModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.Map;

@Cmd(code = GameProtocol.S_DRAGONBOATRACE_DISTANCE_AND_RECEIVED_INFO_FROM_CROSS, desc = " 赛龙舟联盟距离和领取信息   跨服返回区服 协议")
public class DragonBoatRaceGetDistanceAndReceivedInfoFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        DragonBoatRaceProto.DragonBoatRaceSynUnionInfoCrossToGameMsg builder = DragonBoatRaceProto.DragonBoatRaceSynUnionInfoCrossToGameMsg.parseFrom(packet.getBytes());
        if (builder.getType() == 0) {
            Map<Long, CrossUnionMember> memberMap = CrossUnionMgr.getUnionMemberMap(builder.getUnionId());
            for (CrossUnionMember item : memberMap.values()) {
                GamePlayer player = GamePlayerMgr.getOnlinePlayer(item.getUserId());
                if (player != null) {
                    player.getModule(DragonBoatRaceModule.class).synRedPoint(builder);
                }
            }
        } else {
            GamePlayer player = GamePlayerMgr.getOnlinePlayer(packet.getPlayerId());
            if (player != null) {
                player.getModule(DragonBoatRaceModule.class).synRedPoint(builder);
            }
        }
    }
}
